/*
 * Name: UserData
 * Author: Sam Oakley
 * Date: 4/4/2010
 * Version Number: 1.1
 * Description: User database class. Handles creating a database on first use and
 * deleting it on app version change
 * Changes History: 
 * 1.0 Created class
 * 1.1 Added address fields
 */
package com.blork.rag;

import static android.provider.BaseColumns._ID;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

public class UserData extends SQLiteOpenHelper{
	private static final String DATABASE_NAME = "user.db";
	private static final int DATABASE_VERSION = 22;
	
	/** Create a helper object for the Events database */
	public UserData(Context ctx){
		super(ctx, DATABASE_NAME, null, DATABASE_VERSION);
	}
	
	@Override
	public void onCreate(SQLiteDatabase db){
		db.execSQL("CREATE TABLE user (" 
				+_ID+ " INTEGER PRIMARY KEY AUTOINCREMENT, " +
						"first_name TEXT NOT NULL," +
						"last_name TEXT NOT NULL," +
						"dob TEXT NOT NULL," +
						"just_giving_url TEXT," +
						"gender TEXT NOT NULL," +
						"mobile TEXT NOT NULL," +
						"email TEXT NOT NULL," +
						"uni TEXT," +
						"ucard TEXT," +
						"address1 TEXT," +
						"address2 TEXT," +
						"city TEXT," +
						"postcode TEXT," +
						"homephone TEXT," +
						"passport_no TEXT," +
						"hoody_size TEXT," +
						"tshirt_size TEXT," +
						"docName TEXT," +
						"docSurgery TEXT," +
						"docAddress1 TEXT," +
						"docAddress2 TEXT," +
						"docCity TEXT," +
						"docPostcode TEXT," +
						"docPhone TEXT," +
						"docConditions TEXT," +
						"emName TEXT," +
						"emRelationship TEXT," +
						"emAddress1 TEXT," +
						"emAddress2 TEXT," +
						"emCity TEXT," +
						"emPostcode TEXT," +
						"emPhone TEXT);");
	}
	@Override
	public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion){
		db.execSQL("DROP TABLE IF EXISTS user");
		onCreate(db);
	}
}
